package org.bangumibuddy.controller;

import lombok.extern.slf4j.Slf4j;
import org.bangumibuddy.entity.AnimeEntity;
import org.bangumibuddy.pojo.anime.AnimeSummary;
import org.bangumibuddy.pojo.ResponseResult;
import org.bangumibuddy.service.AnimeService;
import org.bangumibuddy.vo.AnimeOverviewVO;
import org.bangumibuddy.vo.AnimeSummaryVO;
import org.bangumibuddy.vo.TorrentStatusVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/anime")
public class AnimeController {

    @Autowired
    private AnimeService animeService;

    @GetMapping("/list")
    public ResponseResult<List<AnimeOverviewVO>> getBangumiList() {
        List<AnimeEntity> animas = animeService.getAnimaList();
        List<AnimeOverviewVO> animeOverviewVOList = new ArrayList<>();
        for(AnimeEntity anima : animas) {
            AnimeOverviewVO animeOverviewVO = new AnimeOverviewVO();
            animeOverviewVO.setId(anima.getId());
            animeOverviewVO.setTitle(anima.getName());
            animeOverviewVO.setSubTitle(anima.getSeason());
            animeOverviewVO.setPoster(anima.getPoster());
            animeOverviewVOList.add(animeOverviewVO);
        }

        return ResponseResult.success(animeOverviewVOList);
    }

    @GetMapping("/summary/{id}")
    public ResponseResult<AnimeSummaryVO> getAnimaSummary(@PathVariable Long id) {
        AnimeSummary animeSummary = animeService.getAnimaSummary(id);
        AnimeSummaryVO animeSummaryVO = new AnimeSummaryVO();
        animeSummaryVO.setSeason(animeSummary.getSeason());
        animeSummaryVO.setTitle(animeSummary.getName());
        animeSummaryVO.setSubtitle(animeSummary.getSeason());
        animeSummaryVO.setPoster(animeSummary.getPoster());
        animeSummaryVO.setYear(animeSummary.getYear().toString());
        BeanUtils.copyProperties(animeSummary, animeSummaryVO);

        return ResponseResult.success(animeSummaryVO);
    }

}
